mod pdf_rs;
mod wkhtmltopdf;
mod html2pdf;
mod image_crop;
mod mupdf_test;

fn main() {
    println!(">>>>hello, convert pdf");
}

#[cfg(test)]
mod test {
    use std::path::Path;
    use std::time::Duration;

    use headless_chrome::LaunchOptions;
    use headless_chrome::types::PrintToPdfOptions;

    use crate::html2pdf::html_to_pdf;

    /*#[test]
        fn test_wkhtml2pdf() {
            let html = r#"<html><body><div>foo</div></body></html>"#;
            let mut pdf_app = PdfApplication::new().expect("Failed to init PDF application");
            let mut pdfout = pdf_app
                .builder()
                .orientation(Orientation::Landscape)
                .margin(Size::Inches(2))
                .title("Awesome Foo")
                .build_from_html(&html)
                .expect("failed to build pdf");

            pdfout.save("foo.pdf").expect("failed to save foo.pdf");
            println!("generated PDF saved as: foo.pdf");
        }*/

    #[test]
    fn test_html2pdf() {
        let pdf_options = PrintToPdfOptions {
            landscape: Some(true),
            display_header_footer: None,
            print_background: Some(true),
            scale: Some(1.0_f64),
            paper_width: None,
            paper_height: None,
            margin_top: Some(0_f64),
            margin_bottom: Some(0_f64),
            margin_left: Some(0_f64),
            margin_right: Some(0_f64),
            page_ranges: None,
            ignore_invalid_page_ranges: None,
            header_template: None,
            footer_template: None,
            prefer_css_page_size: None,
            transfer_mode: None,
        };
        let _launch_options = LaunchOptions {
            headless: false,
            sandbox: false,
            devtools: false,
            enable_gpu: false,
            enable_logging: false,
            window_size: None,
            port: None,
            ignore_certificate_errors: false,
            path: None,
            user_data_dir: None,
            extensions: vec![],
            args: vec![],
            ignore_default_args: vec![],
            disable_default_args: false,
            idle_browser_timeout: Default::default(),
            process_envs: None,
            proxy_server: None,
        };
        let wait = Some(Duration::from_secs(1));

        let i_path = Path::new("K:\\rust\\src\\ymrz-rs.gitee.com\\tera-template-rs\\templates\\catacure.html");
        let o_path = Path::new("K:\\rust\\src\\ymrz-rs.gitee.com\\tera-template-rs\\templates\\catacure.pdf");
        html_to_pdf(i_path, o_path, pdf_options, LaunchOptions::default(), None).expect("pdf转换错误");
    }
}
